# -*- coding: utf-8 -*-

__author__ = 'sergey'

def get_file_logger(name):

    import os
    import logging
    from logging.handlers import TimedRotatingFileHandler

    log = logging.getLogger(name)
    log.setLevel(logging.DEBUG)

    file_path = os.path.abspath( "log/%s.log" % name )
    dir_path = os.path.dirname(file_path)
    if not os.path.isdir(dir_path):
        os.makedirs(dir_path)

    hnd = TimedRotatingFileHandler(file_path, when="d", backupCount=7)

    fmt = logging.Formatter("%(asctime)s | %(name)s[%(levelname)s] : %(message)s")
    hnd.setFormatter(fmt)

    log.addHandler(hnd)

    return log